﻿using System;
using UniRx;

public abstract partial class FSMBase : UnitComponentBase
{
    /// <summary>
    /// 状态机过渡
    /// </summary>
    protected class FSMTransition : IEquatable<FSMTransition>
    {
        /// <summary>
        /// 过渡来源
        /// </summary>
        public FSMStateBase source { get; set; }

        /// <summary>
        /// 过渡目标
        /// </summary>
        public FSMStateBase target { get; set; }

        /// <summary>
        /// 优先级。数值越大，优先级越高，相同优先级之间不互相覆盖
        /// </summary>
        public int priority { get; set; }

        /// <summary>
        /// 判定流
        /// </summary>
        public IObservable<Unit> stream { get; set; }

        /// <summary>
        /// 判定回调
        /// </summary>
        public Func<bool> condition { get; set; }

        /// <summary>
        /// 过渡比率，用于动画的过渡计算
        /// </summary>
        public float fade { get; set; } = 0f;


        public bool Equals(FSMTransition other)
        {
            return source == other.source &&
                target == other.target &&
                stream.Equals(other.stream) &&
                condition.Equals(other.condition);
        }
    }
}